// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLHint;
// import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
// import com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleReturningClause;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "OracleDeleteStatement.h"
#include "../../../../../DbType.h"
#include "../../../../ast/SQLHint.h"
#include "../../../../ast/statement/SQLTableSource.h"
#include "../clause/OracleReturningClause.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "../../../../../utils/listTran.h"

OracleDeleteStatement::OracleDeleteStatement()
    : SQLDeleteStatement(DbType_ptr(new DbType(&DbType::oracle)))
{
  hints = std::make_shared<std::list<SQLHint_ptr>>();
}

OracleReturningClause_ptr OracleDeleteStatement::getReturning()
{
  return returning;
}

void OracleDeleteStatement::setReturning(OracleReturningClause_ptr returning)
{
  this->returning = returning;
}

SQLHint_list_ptr OracleDeleteStatement::getHints()
{
  return this->hints;
}

void OracleDeleteStatement::accept0(SQLASTVisitor_ptr visitor)
{
  accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
}

void OracleDeleteStatement::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleDeleteStatement)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLHint, SQLObject>(this->hints);
    acceptChild(visitor, tmp1);
    acceptChild(visitor, this->tableSource);
    acceptChild(visitor, this->getWhere());
    acceptChild(visitor, returning);
  }

  visitor->endVisit(SharedObject(OracleDeleteStatement));
}

SQLObject_ptr OracleDeleteStatement::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleDeleteStatement>(new OracleDeleteStatement());
  std::shared_ptr<OracleDeleteStatement> x = std::dynamic_pointer_cast<OracleDeleteStatement>(clone_tmp);
  // OracleDeleteStatement x = new OracleDeleteStatement();
  cloneTo(x);

  for (SQLHint_ptr hint : *hints)
  {
    SQLHint_ptr hint2 = std::dynamic_pointer_cast<SQLHint>(hint->clone());
    hint2->setParent(x);
    x->hints->push_back(hint2);
  }
  if (returning != nullptr)
  {
    x->setReturning(std::dynamic_pointer_cast<OracleReturningClause>(returning->clone()));
  }

  return x;
}
